﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SudokuGame.Sudoku
{
    public class IdValues
    {
        public string Id { get; set; }
        public string Value { get; set; }
        public string Value2 { get; set; }
        public string Value3 { get; set; }
        public string Value4 { get; set; }
        public string Value5 { get; set; }
        public int Standby { get; set; }
        public string Display { get; set; }
        public static bool operator ==(IdValues idValues, IdValues idValues2)
        {
            return idValues.Equals(idValues2);
        }
        public static bool operator !=(IdValues idValues, IdValues idValues2)
        {
            return !idValues.Equals(idValues2);
        }
        public override int GetHashCode()
        {
            var code = (Id, Value, Value2, Value3, Value4, Value5, Standby).GetHashCode();
            return code;
        }
        public override bool Equals(object? obj)
        {
            return obj?.GetHashCode() == GetHashCode();
        }
        const int TARGET = 0x1F;
        /// <summary>
        /// 将连续字段的哈希代码左移两位或更多位来加权各个哈希代码(最佳情况下，超出位 31 的位应环绕，而不是被丢弃)
        /// </summary>
        /// <param name="value"></param>
        /// <param name="positions"></param>
        /// <returns></returns>
        public int ShiftAndWrap(int value, int positions = 3)
        {
            positions &= TARGET;
            uint number = BitConverter.ToUInt32(BitConverter.GetBytes(value), 0);
            uint wrapped = number >> (32 - positions);
            return BitConverter.ToInt32(BitConverter.GetBytes((number << positions) | wrapped), 0);
        }
    }
}
